package listbyorder.access101_200.test189;

import java.util.Stack;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/15 12:56
 */
public class Solution2 {

    // 利用辅助栈
    public void rotate(int[] nums, int k) {
        int len = nums.length;
        if (k != len) {
            k %= len;
            Stack<Integer> stack = new Stack<>();
            int pre = len - k;
            for (int i = 0; i < pre; i++) {
                stack.push(nums[i]);
            }

            for (int i = 0; i < k; i++) {
                nums[i] = nums[pre + i];
            }
            for (int i = len - 1; i >= k; i--) {
                nums[i] = stack.pop();
            }
        }
    }

}
